const inquirer = require("inquirer");
const t = require("../config/dict");
const { sources } = require("../config");
const config = require("../mfo.config.js");
const _LOCALSOURCE = process.env.LOCALSOURCE || config.LOCALSOURCE;

module.exports = (context) => {
  const defaultSelected = sources.filter((item) => item.value === _LOCALSOURCE);
  return inquirer
    .prompt([
      {
        name: "projectLocalSource",
        message: t(context.lang, "选择源") + "?",
        default: defaultSelected[0].name,
        pageSize: sources.length + 2,
        type: "rawlist",
        choices: [
          ...t(context.lang, sources),
          {
            name: t(context.lang, "取消"),
            value: "cancel",
          },
        ],
      },
    ])
    .then((answers) => {
      if (answers.projectLocalSource === "cancel") {
        context.source = _LOCALSOURCE;
      } else context.source = answers.projectLocalSource;
      return context;
    });
};
